<?php 
	require 'Model.php';
	class indexModel extends Model{
		function __Construct(){
			parent::__Construct();
		}

		//获取视频类别列表
		function getvideotype(){
			$sql="select * from videotype";
			$vt_list = $this->conn->query($sql);
			return $vt_list;
		}
		//获取点击排行列表
		function gethittimes(){
			$sql="select * from videos order by hittimes desc limit 0,4";
			$hits_list = $this->conn->query($sql);
			return $hits_list;
		}
		//获取视频信息
		function getvideoinfor(){
			$sql_vt="select * from videotype";
			$data = $this->conn->query($sql_vt);
			$v_list=array();
			foreach($data as $one)
			{
				$sql="select * from videos where tid=".$one['tid']." order by vid desc limit 0,6";

				$vlist=array();
				$vlist['tid']=$one['tid'];
				$vlist['typename']=$one['typename'];
				$vlist['list']=$this->conn->query($sql);
				$v_list[]=$vlist;
			}
			return $v_list;
		}

		function getvideolist($id){
			$sql="select * from videotype where tid=".$id;
			$list=$this->conn->query($sql);
			$video_list=array();
			$vtsql="select * from videos where tid=".$id;
			$videolist=array();
			$videolist['tid']=$list['tid'];
			$videolist['typename']=$list['typename'];
			$videolist['list']=$this->conn->query($vtsql);
			$video_list[]=$videolist; 
			return $video_list;
		}

		function fetch_one($sql,$result_type=MYSQL_ASSOC)
		{
		    $result=mysql_query($sql);
		    if ($result && mysql_num_rows($result)>0)
		    {
		        return mysql_fetch_array($result,$result_type);
		    }
		    else
		    {
		        return false;
		    }
		}

		function getvideoshow($id){
			$sql='select videos.*,comments.* from videos left join comments on videos.vid=comments.vid where videos.vid='.$id.'';
   			$show=$this->fetch_one($sql);
   			return $show;
		}
	}

?>